package com.sanbi.shield.client.auto;

import com.sanbi.shield.client.core.aop.ClientIdempotentAspect;
import com.sanbi.shield.client.core.aop.IdempotentRetryJob;
import com.sanbi.shield.client.core.idempotent.ClientIdempotentBeanProcessor;
import com.sanbi.shield.client.core.interfaces.ClientIdempotentManager;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;

/**
 * Client幂等自动配置类
 *
 * @author XiaoQingqing
 * @since 2024/08/22
 */
@Configuration
@EnableScheduling
@ConditionalOnProperty(prefix = "shield.client.idempotent", name = "enabled", havingValue = "true")
public class ClientIdempotentAutoconfigure {

    @Bean
    public ClientIdempotentBeanProcessor clientIdempotentBeanProcessor(){
        return new ClientIdempotentBeanProcessor();
    }

    @Bean
    public ClientIdempotentAspect clientIdempotentAspect(ClientIdempotentManager manager){
        return new ClientIdempotentAspect(manager);
    }

    @Bean
    public IdempotentRetryJob idempotentRetryJob(ClientIdempotentManager manager){
        return new IdempotentRetryJob(manager);
    }
}
